﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Mvc;
using WebStorage.Models;

namespace WebStorage.Controllers
{
    [SkipCheckLogin]
    public class LoginController : Controller
    {
        DbHelper Helper = new DbHelper();
        // GET: Login
        public ActionResult Index()
        {
            Session["User"] = null;
            Session.Clear();
            return View(new WebUser());
        }

        [HttpPost]
        public JsonResult Check(string name, string password)
        {
            JsonObj obj = new JsonObj();
            var user = Helper.Login(name, password);
            if (user != null)
            {
                Session["User"] = user;
                obj.code = 200;
                obj.info = "success";
            }
            else
            {
                obj.code = 404;
                obj.info = "user not exists";
            }

            return Json(obj);
        }
    }

    public class JsonObj
    {
        public int code { get; set; }
        public string info { get; set; }
    }
}